package com.example.mymvp;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.List;

public class Adapter extends ArrayAdapter<Start> {
    private int resourceid;
    private TextView txt1,txt2;
    private ImageView img;
    public Adapter(@NonNull Context context, int resource, @NonNull List<Start> objects) {
        super(context, resource, objects);
        resourceid = resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        Start start = getItem(position);
        if (convertView == null){
            convertView = LayoutInflater.from(getContext()).inflate(resourceid,parent,false);
        }
        img = convertView.findViewById(R.id.iage);
        txt1 = convertView.findViewById(R.id.txt1);
        txt2 = convertView.findViewById(R.id.txt2);
        img.setImageResource(start.getImgid());
        txt1.setText(start.getName());
        txt2.setText(start.getFans());

        return convertView;
    }
}
